package promote.brozen.algorithm.leetcode._881;

import java.util.Arrays;

/**
 * @author Brozen
 * @date 2020/9/5 2:15 PM
 * @email brozen@qq.com
 */
public class Ship {


    public int numRescueBoats(int[] people, int limit) {
        Arrays.sort(people);
        int shipNum = 0;
        int i = 0, j = people.length - 1;
        for (; i < j; ) {
            if (people[j] + people[i] <= limit) {
                i++;
            }

            j--;
            shipNum++;
        }

        if (i == j) {
            shipNum++;
        }
        return shipNum;
    }

}
